// pages/manager.js
Page({
  data: {
    device:"",
    status:'在线',
    outfood:"0",
    startViewStyle:"",
    nextyear:"2023",
    nextmonth:"9",
    nextday:"12",
    nexthour:"11",
    nextminute:"30",
    nextfood:"3",
    todayfood:"778",
    totalremain:"1314",
    bowlremain:"88",
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(options) {
    const device = options.device;
    this.setData({device:device});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    wx.request({
      url: 'http://114.132.70.44:2000/bucket_basin',
      data:{"id":this.data.device},
      method:'POST',
      success: function (res) {
        if (res.statusCode === 200) {
          var responseData = res.data;
          that.setData({totalremain:responseData})
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  updateStartViewStyle: function () {
    const outfood = this.data.outfood;
    const startViewStyle = outfood > 0 ? "background-color: #00B26A; cursor: pointer;color:white" : "";
    this.setData({
      startViewStyle: startViewStyle
    });
  },

  reduce:function(){
    let outfood1 = this.data.outfood;
    if(outfood1>0)
    {
        outfood1--;
        this.setData({outfood:outfood1});
    }
    this.updateStartViewStyle();
  },
  plus:function(){
    let outfood1 = this.data.outfood;
    outfood1++;
    this.setData({outfood:outfood1});
    this.updateStartViewStyle();
  },
  startTap:function(){
    console.log('CuteCat get '+this.data.outfood +' food.');
    wx.request({
      url: 'http://114.132.70.44:2000/feed',
      data:{"id":this.data.device,"amount":this.data.outfood},
      method:'POST'
    })
  },
  checkRecord:function(){
    wx.navigateTo({
      url: `../foodrecord/foodrecord?deviceName=${this.data.device}`,
    })
  },
  configurefood:function(){
    wx.navigateTo({
      url: `../addfood/addfood?deviceName=${this.data.device}`,
    })
  }
})